package top.bulk.demo.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.bulk.demo.filter.BulkFilter1;
import top.bulk.demo.filter.BulkFilter2;

import javax.servlet.Filter;

/**
 * @author 散装java
 * @version 1.0.0
 * @date 2022-11-13
 */
@Configuration
public class FilterRegistrationConfig {
    @Bean
    public FilterRegistrationBean<Filter> filter1() {
        FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
        //设置过滤器名称
        filterRegistrationBean.setFilter(new BulkFilter1());
        //配置过滤规则
        filterRegistrationBean.addUrlPatterns("/*");
        //order的数值越小 则优先级越高
        filterRegistrationBean.setOrder(2);
        return filterRegistrationBean;
    }
    @Bean
    public FilterRegistrationBean<Filter> filter2() {
        FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
        //设置过滤器名称
        filterRegistrationBean.setFilter(new BulkFilter2());
        //配置过滤规则
        filterRegistrationBean.addUrlPatterns("/*");
        //order的数值越小 则优先级越高
        filterRegistrationBean.setOrder(1);
        return filterRegistrationBean;
    }
}
